using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace OurWedding1.Models
{ 
    public class ExpenseTypeRepository : IExpenseTypeRepository
    {
        WeddingEntities context = new WeddingEntities();

        public IQueryable<ExpenseType> All
        {
            get { return context.ExpenseTypes; }
        }

        public IQueryable<ExpenseType> AllIncluding(params Expression<Func<ExpenseType, object>>[] includeProperties)
        {
            IQueryable<ExpenseType> query = context.ExpenseTypes;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public ExpenseType Find(int id)
        {
            return context.ExpenseTypes.Find(id);
        }

        public void InsertOrUpdate(ExpenseType expensetype)
        {
            if (expensetype.ExpenseTypeId == default(int)) {
                // New entity
                context.ExpenseTypes.Add(expensetype);
            } else {
                // Existing entity
                context.Entry(expensetype).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var expensetype = context.ExpenseTypes.Find(id);
            context.ExpenseTypes.Remove(expensetype);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IExpenseTypeRepository : IDisposable
    {
        IQueryable<ExpenseType> All { get; }
        IQueryable<ExpenseType> AllIncluding(params Expression<Func<ExpenseType, object>>[] includeProperties);
        ExpenseType Find(int id);
        void InsertOrUpdate(ExpenseType expensetype);
        void Delete(int id);
        void Save();
    }
}